package com.hit.eduService.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hit.commonUtils.R;
import com.hit.eduService.entity.EduCourse;
import com.hit.eduService.entity.chapter.ChapterVo;
import com.hit.eduService.entity.frontVo.CourseQueryVo;
import com.hit.eduService.entity.frontVo.CourseWebVo;
import com.hit.eduService.service.EduChapterService;
import com.hit.eduService.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("eduService/courseFront")
@CrossOrigin
public class CourseFrontController {

    @Autowired
    private EduChapterService chapterService;
    @Autowired
    private EduCourseService eduCourseService;

    //1.根据前端传入的筛选条件分页返回课程
    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseList(@PathVariable long page, @PathVariable long limit, @RequestBody(required = false) CourseQueryVo courseQueryVo){
        Page<EduCourse> pageCourse=new Page<>(page,limit);
        Map<String,Object> map=eduCourseService.getCourseFrontList(pageCourse,courseQueryVo);
        return R.ok().data(map);
    }

    //2 课程详情的方法
    @GetMapping("getFrontCourseInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId) {
        //根据课程id，编写sql语句查询课程信息
        CourseWebVo courseWebVo = eduCourseService.getBaseCourseInfo(courseId);

        //根据课程id查询章节和小节
        List<ChapterVo> chapterVideoList = chapterService.getChapterVideoById(courseId);

        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVideoList);
    }
}
